#include <bits/stdc++.h>
using namespace std;

// #define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

typedef long long LL;

int t, n;
const int N = 1e5+50;

int x;

char s[N];

int main(int argc, char const *argv[])
{
	scanf("%d", &t);
	for (int kk=0; kk<t; ++kk)
	{
		scanf("%d%d", &n, &x);
		scanf("%s", s);

		unordered_map<int, int> mp;
		int tot = 0;
		for (int i=0; i<n; ++i)
		{
			if (s[i] == '0') ++tot;
			else --tot;
			mp[tot]++;
		}
		if (tot == 0)
		{
			if (mp.count(x)) puts("-1");
			else puts("0");
			continue;
		}
		LL ans = 0;
		if (x == 0) ++ans;
		for (const auto &p:mp)
		{
			int bal = p.first, times = p.second;
			int need = x - bal;
			dbg(need, tot, need / tot);
			if (need % tot == 0 && need / tot >= 0)
			{
				ans += times;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}